package com.ruoyi.receipt.utils;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;

import static com.ruoyi.common.utils.reflect.ReflectUtils.setFieldValue;

/**
 * 初始化后端用户信息
 * 
 * @author chenjian
 */
public class UserInitUtils
{

    public static void initUserInfo(Object obj){

        try {
            LoginUser loginUser = SecurityUtils.getLoginUser();
            setFieldValue(obj,"createId" , loginUser.getUser().getUserId());
            setFieldValue(obj,"updateId" , loginUser.getUser().getUserId());
            setFieldValue(obj,"createTime" ,  DateUtils.getNowDate());
            setFieldValue(obj,"updateTime" ,  DateUtils.getNowDate());
        } catch (Exception exception) {
            exception.printStackTrace();
        }

    }

    public static void initUserInfoForUpdate(Object obj){

        try {
            LoginUser loginUser = SecurityUtils.getLoginUser();
            setFieldValue(obj,"updateId" , loginUser.getUser().getUserId());
            setFieldValue(obj,"updateTime" ,  DateUtils.getNowDate());
        } catch (Exception exception) {
            exception.printStackTrace();
        }

    }

}
